
<template>
  <!-- 合同续签页面 -->
  <!-- ContractMaintenance -->
  <div class="renewal Maintain">
    <el-form class="my-search-form-box" :model="page.params" inline>
      <div class="my-search-form-left">
        <!-- 年度 -->
        <el-form-item label="年度：">
          <el-select
            filterable
            clearable
            @change="handleSearch"
            v-model="page.params.year"
            placeholder="请选择"
          >
            <el-option
              v-for="item in years"
              :key="item"
              :label="item"
              :value="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--合同名称  -->
        <!-- <el-form-item label="合同名称："
                      prop="projectname">
          <el-input @change="conname"
                    clearable
                    v-model="page.params.projectname"
                    placeholder="请输入"></el-input>
        </el-form-item> -->
        <!-- 合同类别  -->
        <!-- <el-form-item label="合同类别：">
          <el-select filterable
                     clearable
                     @change="contype"
                     v-model="page.params.category"
                     placeholder="请选择">
            <el-option v-for="item in ctypedata"
                       :key="item.key"
                       :label="item.name"
                       :value="item.key"></el-option>
          </el-select>
        </el-form-item> -->
        <!-- 单位名称 -->
        <!-- <el-form-item label="单位名称："
                      class="formbox"
                      prop="winner">
          <el-input @change="ybpro"
                    clearable
                    v-model="page.params.winner"
                    placeholder="请输入" />
        </el-form-item> -->
        <!-- 政采分类 -->
        <el-form-item label="采购类别：">
          <el-select
            filterable
            clearable
            @change="protype"
            v-model="page.params.isgovprocurement"
            placeholder="请选择"
          >
            <el-option
              v-for="item in this.polidatas"
              :key="item.key"
              :label="item.name"
              :value="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 中标供应商：-->
        <!-- <el-form-item label="中标供应商："
                      class="formbox"
                      prop="winner">
          <el-input @change="ybpro"
                    clearable
                    v-model="page.params.winner"
                    placeholder="请输入" />
        </el-form-item> -->
        <!-- 项目名称 -->
        <el-form-item label="项目名称：" class="formbox" prop="winner">
          <el-input
            @change="ybpro"
            clearable
            v-model="page.params.winner"
            placeholder="请输入"
          />
        </el-form-item>
        <!-- 状态-->
        <!-- <el-form-item label="状态：">
          <el-select filterable
                     clearable
                     @change="cgestate"
                     v-model="page.params.state"
                     placeholder="请选择">
            <el-option v-for="item in statedata"
                       :key="item.key"
                       :label="item.state"
                       :value="item.state"></el-option>
          </el-select>
        </el-form-item> -->
        <!-- 单位资质 -->
        <!-- <el-form-item label="单位资质：">
          <el-select filterable
                     style="width:100%"
                     clearable
                     @change="naturedes"
                     v-model="page.params.nature"
                     placeholder="请选择">
            <el-option v-for="item in gyst"
                       :key="item.key"
                       :label="item.name"
                       :value="item.name"></el-option>
          </el-select>
        </el-form-item> -->
      </div>
      <!-- button -->
      <!-- <div class="my-search-form-right"
           style="margin-left:15px;">
        <el-button type="primary"
                   @click="daochubutton">导出</el-button>
        <el-button type="primary"
                   @click="newadd">新增</el-button>
      </div> -->
      <div class="my-search-form-right" style="margin-left: 15px">
        <!-- <el-button type="primary"
                   @click="daochubutton('新增电子化平台')">新增电子化平台</el-button>
        <el-button type="primary"
                   @click="daochubutton('新增5W-10W')">新增5W-10W
        </el-button>
        <el-button type="primary"
                   @click="daochubutton('新增5W以下')">新增5W以下
        </el-button> -->
        <el-button type="primary" @click="daochubutton"> 新增合同 </el-button>
        <!-- <el-button type="primary"
                   @click="daochubutton('新增10W-50W')">新增10W-50W</el-button> -->
      </div>
    </el-form>
    <!-- 表格 -->
    <my-table-pagination
      :data="tableData"
      :page.sync="page"
      :tableHeight="230"
      @pageCurrentChange="apigetTableData_new"
      @pageSizeChange="apigetTableData_new"
      @handleMyTableButtonClick="handleTableButtonClick"
      :tableColumns="tableColumns"
      class="table-box"
    >
      <el-table-column align="center" slot="img" width="120px" label="附件">
        <template slot-scope="{ row }">
          <div style="color: #409eff" v-if="row.state == '通过'">
            <span
              style="padding: 0 4px; cursor: pointer"
              @click="btn_filse(row, 0)"
              >查看</span
            >
            <span
              style="padding: 0 4px; cursor: pointer"
              @click="btn_filse(row, 1)"
              >下载</span
            >
          </div>
        </template>
      </el-table-column>
    </my-table-pagination>
    <!-- 编辑 页面-->
    <el-dialog
      :title="dialogVisibless"
      :visible.sync="dialogVisible"
      width="100%"
      fullscreen
      :before-close="handleClose"
      center
    >
      <renewalAddVue
        v-if="dialogVisible"
        :child="editpages"
        :showFlag="showFlag"
      />
    </el-dialog>
    <!-- 新增    -->
    <el-dialog
      :visible.sync="dialogVisibleadd"
      width="100%"
      fullscreen
      :before-close="handleClose"
      title="新增续签"
      center
    >
      <newadd v-if="dialogVisibleadd" />
    </el-dialog>
    <!-- 详情 页面-->
    <el-dialog
      title="合同详情"
      :visible.sync="detaildialog"
      width="100%"
      fullscreen
      :before-close="handleClose"
      center
    >
      <renewalDetails
        v-if="detaildialog"
        :son="detailsdata"
        :list_details="list_details"
      />
    </el-dialog>
    <!-- new 详情页面 -->

    <el-dialog
      :visible.sync="dialogVisibleadd_1"
      width="100%"
      fullscreen
      :before-close="handleClose"
      :title="list_details.projectname ? list_details.projectname : '合同维护'"
      center
    >
      <DetailsS
        v-if="dialogVisibleadd_1"
        :list_details="list_details"
        :son="detailsdata"
      />
      <!-- <newDetails v-if="dialogVisibleadd_1"
                :list_details="list_details"
                :son="detailsdata" /> -->
    </el-dialog>
    <!-- 新增合同 new_add-->
    <el-dialog
      :visible.sync="dialogVisibleadd_2"
      width="100%"
      fullscreen
      class="newAddclass"
      :before-close="handleClose_2"
      :title="list_details.projectname ? list_details.projectname : '新增合同'"
      center
    >
      <!-- <DetailsS v-if="dialogVisibleadd_1"
                :list_details="list_details"
                :son="detailsdata" /> -->
      <newDetails
        v-if="dialogVisibleadd_2"
        :list_details="list_details"
        :son="detailsdata"
      />
    </el-dialog>

    <!-- <el-dialog :visible.sync="detaildialog_filse"
               width="100%"
               fullscreen
               title="附件查看"
               :before-close="handleClose_filse"
               center>
      <iframe :src="sqbList"
              style="width:100%;height:100%"
              frameborder="0"></iframe>
    </el-dialog> -->
  </div>
</template>

<script>
import myUpload from '@/components/global/my-upload/main.vue'
import { getUserInfo } from '@/utils/sessionStorage'
import newadd from '../renewal/newadd'
import renewalAddVue from '../renewal/renewalAdd'
import renewalDetails from './components/xiangqing.vue'
import DetailsS from './components/Details_s.vue'
import newDetails from './components/new_add.vue'
export default {
  name: 'renewal',
  components: {
    renewalAddVue,
    renewalDetails,
    newadd,
    DetailsS,
    newDetails,
    myUpload,
  },
  data() {
    return {
      detaildialog_filse: false,
      list_details: {
        name: '测试',
      },
      dialogVisible: false,
      detaildialog: false,
      dialogVisibleadd: false,

      dialogVisibless: '新增合同',
      userInfo: getUserInfo(),

      detailsdata: {},
      tableColumns: [
        {
          label: '序号',
          type: 'index',
          width: 60,
          align: 'center',
        },
        {
          label: '合同编号',
          prop: 'contractnum',
          align: 'left',
          width: '210',
        },
        {
          label: '状态',
          prop: 'state',
          align: 'center',
          width: '120',
        },
        {

          label: '开标时间',
          prop: 'startTime',
          align: 'center',
          width: '160',

        },
        {
          label: '合同名称',
          prop: 'projectname',
          align: 'left',
        },
        {
          label: '采购类别',
          prop: 'isgovprocurement',
          width: '140',
        },






        {
          label: '合同金额（元）',
          prop: 'amount',
          align: 'rigth',
          isSum: true,
          width: '140',
        },
        {
          label: '预算金额（元）',
          prop: 'budget',
          align: 'left',
          width: '140',
          isSum: true,
        },






        {
          label: '操作',
          editor: true,
          width: 120,
        },




      ],
      tableData: [],
      page: {
        current: 1,
        size: 20,
        total: 0,
        params: {

          year: '',

          isgovprocurement: '',

          projectname: '',

          category: '',

          winner: '',

          state: '',
          nature: '',
        },
      },

      editpages: {},

      years: [],

      polidatas: [],

      ctypedata: [],

      statedata: [],

      gyst: [],

      daochulist: [],
      dialogVisibleadd_1: false,
      dialogVisibleadd_2: false,
    }
  },
  created() {

    this.apigetYearList()
    this.apigetPolicyList()
    this.apigetStateList()
    this.apigetCtypeLsit()
    this.apigetGysTypeList()

    this.apigetTableData_new()
    if (this.$route.query.cid) {
      this.list_details.cid = this.$route.query.cid
      this.list_details = this.$route.query
      console.log(this.list_details);
      this.daochubutton()
    }
    this.tableData = []
  },
  methods: {

    handleClick(value, row) {

    },

    daochubutton(e) {
      console.log(e);
      if (e == 'supple') {
        this.detailsdata.bulu__ = "supple";
        this.detailsdata.xiangqing__ = true
        this.dialogVisibleadd_1 = true
      } else {
        this.detailsdata.type_xz = false
        this.detailsdata.xiangqing__ = false
        this.detailsdata.bulu__ = ''

        this.detailsdata = {}
        if (this.$route.query.cid == null) {
          this.list_details = {}
        }
        this.dialogVisibleadd_2 = true
      }



    },

    newadd() {

      this.dialogVisibleadd = true




    },

    apigetTableData_new() {
      console.log(this.page)
      this.page.params.projectname = this.page.params.winner
      this.page.params.govprocurement = this.page.params.isgovprocurement
      this.$axios.post('/info/contractVo/getPage', this.page).then((res) => {
        let { data } = res.data
        console.log(data)
        if (data) {
          data.records.forEach((a) => {
            console.log(a)
            if (a.startTime) {
              a.startTime = a.startTime.slice(0, 10)
            }
            if (a.othernum) {
              a.contractnum = a.contractnum + ' (' + a.othernum + ')'
            }
          })
          this.tableData = data.records
          this.page.current = data.current
          this.page.size = data.size
          this.page.total = data.total
        }
      })
    },

    apigetTableData() {
      this.$axios
        .post('/info/contractRenewal/getPage', this.page)
        .then((res) => {
          let { data } = res.data
          if (data) {




          }
        })
    },

    handleTableButtonClick(type, item) {
      console.log(type, item)
      this.list_details = item
      if (type === 'sure') {

        this.apidoSure(item)
      } else if (type === 'edit') {

        this.list_details = item
        this.dialogVisibleadd_2 = true

      } else if (type === 'query') {

        this.apigetInfo(item)

      } else if (type === 'delete') {

        this.apidoDelete(item)
      } else if (type === 'supple') {

        this.detailsdata = item
        console.log('dd', this.detailsdata);
        this.daochubutton(type)
      }
    },

    apidoSaveOrUpdate(item) {
      this.$axios.get('/info/contractLower/getInfo/' + item.cid).then((res) => {
        let { data } = res.data
        if (data) {
          this.editpages = data
          this.showFlag = true
          this.dialogVisible = true
          this.dialogVisibless = '编辑合同'
        }
      })
    },

    apigetInfo(item) {
      this.$axios
        .get('/info/contractVo/getInfo/' + this.list_details.cid)
        .then((res) => {
          let { data } = res.data
          if (data) {
            this.detailsdata = data
            this.detaildialog = true
          }
        })
    },

    apidoSure(item) {
      this.$confirm("您正在将项目的状态修改为'确认'是否继续?", '确认提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      })
        .then(() => {
          this.$axios.get('/info/contractVo/doSure/' + item.cid).then((res) => {
            let { data } = res.data
            if (data) {
              this.$message({
                type: 'success',
                message: '操作成功!',
              })

              this.apigetTableData_new()
            }
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消操作',
          })
        })
    },

    apidoDelete(item) {
      this.$confirm('您正在删除该项目，是否继续?', '确认提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      })
        .then(() => {
          this.$axios
            .get('/info/contractVo/doDelete/' + item.cid)
            .then((res) => {
              let { data } = res.data
              if (data) {
                this.$message({
                  type: 'success',
                  message: '删除成功!',
                })
                this.apigetTableData_new()

              }
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          })
        })
    },

    apigetYearList() {
      this.$axios.get('/info/contractCom/getYearList').then((res) => {
        let { data } = res.data
        if (data) {
          this.years = data
        }
      })
    },

    apigetPolicyList() {
      this.$axios.get('/info/contractCom/getTwoPolicyList').then((res) => {
        let { data } = res.data
        if (data) {
          this.polidatas = data
        }
      })
    },

    apigetStateList() {
      this.$axios.get('/info/contract/getStateList').then((res) => {
        let { data } = res.data
        if (data) {
          this.statedata = data
        }
      })
    },

    apigetCtypeLsit() {
      this.$axios.get('/info/contract/getCtypeLsit').then((res) => {
        let { data } = res.data
        if (data) {
          this.ctypedata = data
        }
      })
    },

    apigetGysTypeList() {
      this.$axios.get('/info/purchaseResult/getGysTypeList').then((res) => {
        let { data } = res.data
        if (data) {
          this.gyst = data
        }
      })
    },

    handleClose_filse() {
      this.detaildialog_filse = false
    },
    handleClose_2() {
      this.$router.push({
        query: {}
      })
      this.dialogVisibleadd_2 = false
    },
    handleClose() {
      this.dialogVisible = false
      this.dialogVisibleadd = false
      this.dialogVisibleadd_1 = false
      this.detaildialog = false
    },
    handleSearch() {
      this.page.current = 1

      this.apigetTableData_new()
    },
    protype() {
      this.page.current = 1

      this.apigetTableData_new()
    },
    cgestate() {
      this.page.current = 1

      this.apigetTableData_new()
    },
    naturedes() {
      this.page.current = 1

      this.apigetTableData_new()
    },
    contype() {
      this.page.current = 1

      this.apigetTableData_new()
    },
    conname() {
      this.page.current = 1

      this.apigetTableData_new()
    },
    ybpro() {
      this.page.current = 1

      this.apigetTableData_new()
    },
  },
}
</script>

<style lang="scss" scoped>
.newAddclass {
 ::v-deep .el-dialog__body {
    height: calc(100% - 145px);
    min-width: 900px !important;
  }
}
/deep/.el-dialog__body {
  min-width: 1400px;
}

.my-search-form-box {
 ::v-deep.el-form-item__label {
    font-size: 14px;
  }
 ::v-deep.el-input__inner {
    width: 160px;
  }
}
/deep/ .el-dialog__body {
  height: 100%;
}
</style>
